<template>
  <div>
    <a-card :bordered="false">
      <f-search-form  @searchHandler="searchHandler">
        <f-search-form-item label="店铺名称" name="shopName"/>
        <f-search-form-item label="分类" type="select" name="typeId" :data="api.type.list" label-key="typeName" value-key="typeId"/>
        <f-search-form-item label="店铺状态" name="shopState" type="select" :data="api.shop.shopState"></f-search-form-item>
        <f-search-form-item label="联系人" name="linkMan" slot="advanced"/>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="shopId" :scroll="scroll" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.shop">
        <span slot="shopLogo" slot-scope="text, record, index">
          <img v-lazy="record.shopLogo" v-viewer  class="radius-img">
        </span>
        <span slot="companyName" slot-scope="text, record, index">
           <f-elipsis :text="record.companyName" :length="20"></f-elipsis>
        </span>
        <span slot="shopName" slot-scope="text, record, index">
           <f-elipsis :text="record.shopName" :length="20"></f-elipsis>
        </span>
        <span slot="recommend" slot-scope="text, record, index">
          <a-switch v-model="record.recommend==1" checkedChildren="是" unCheckedChildren="否" @change="(checked) => setRecommend(checked,record)"/>
        </span>
        <span slot="shopScore" slot-scope="text, record, index">
           <div class="single-item">
              <div class="row-term">
                  <p><a-tag color="green">店铺评分：<span class="price-value">{{record.shopScore}}</span></a-tag><a-tag color="pink">服务评分：<span class="stock-value">{{record.serviceScore}}</span></a-tag></p>
                  <p><a-tag color="red">物流评分：<span class="price-value">{{record.logisticsScore}}</span></a-tag><a-tag color="red">店铺销量：<span class="price-value">{{record.saleCount}}</span></a-tag></p>
              </div>
          </div>
        </span>
        <span slot="shopState" slot-scope="text, record, index">
            <a-tag color="#108ee9" v-if="text==0">未认证</a-tag>
            <a-tag color="#108ee9" v-if="text==10">违规下架</a-tag>
            <a-tag color="#87d068" v-if="text==1">待审核</a-tag>
            <a-tag color="#f50" v-if="text==2">已上架</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.handleShow(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.shopId)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <shop-drawer ref="modal"></shop-drawer>
    </a-card>
  </div>
</template>
<script>
  import ShopDrawer from './shop_drawer'
  export default {
    name: 'TableList',
    components: {
      ShopDrawer,
      ShopAudit: resolve => {
        require(['./shop_audit.vue'], resolve)
      }
    },
    data() {
      let me = this
      return {
        //列表初始化查询参数
        queryParam: {},
        scroll: { x: 1400 },
        // 表头
        columns: [
          {
            title: 'Logo',
            align: 'center',
            scopedSlots: { customRender: 'shopLogo' }
          },
          {
            title: '店铺名称',
            dataIndex: 'shopName',
            width:'180px',
            scopedSlots: { customRender: 'shopName' }
          },
          {
            title: '企业名称',
            width:'210px',
            dataIndex: 'companyName',
            scopedSlots: { customRender: 'companyName' }
          },
          {
            title: '分类',
            width:'110px',
            dataIndex: 'typeName'
          },
          {
            title: '综合信息',
            align: 'center',
            width:'170px',
            scopedSlots: { customRender: 'shopScore' }
          },
          {
            title: '联系人',
            width:'90px',
            dataIndex: 'linkMan'
          },
          {
            title: '客服电话',
            dataIndex: 'linkTel'
          },
          {
            title: '营业时间',
            width:'150px',
            dataIndex: 'businessHours'
          },
          {
            title: '推荐',
            align: 'center',
            dataIndex: 'recommend',
            fixed: 'right',
            scopedSlots: { customRender: 'recommend' }
          },
          {
            title: '店铺状态',
            align: 'center',
            dataIndex: 'shopState',
            fixed: 'right',
            scopedSlots: { customRender: 'shopState' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: '180px',
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [

          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function(table) {
              table.remove()
            }
          }
        ]
      }
    },
    created() {

    },
    methods: {
      setRecommend(check, record) {
        this.http.post(this, {
          url: this.api.shop.setRecommend,
          data: {
            ids: record.shopId,
            recommend: Number(check)
          },
          success(me, data) {
            record.recommend = data
          }
        })
      }
    }
  }
</script>
<style scoped lang="less" rel="stylesheet/less">

  .single-item {
    text-align: center;
    float: left;
    margin-right: 8px;
    cursor: pointer;
  }

  .single-item .hold-img {
    padding: 5px;
  }


  .single-item p {
    margin: 0px;
    width: 220px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .single-item .spec-title {
    margin-top: 5px;
    color: #00A0E9;
  }

  .single-item .row-term p {
    width: 220px;
    padding-top: 4px;
    text-align: left;
  }


  .row-title {
    display: inline-block;
    text-align: center;
    padding-left: 20px;
  }

</style>
